///////////////////////////////////////////////////////////////////////////////
//
//  Copyright (C) 2007-2009 ILOG, S.A.
//  All Rights Reserved.
//  The following is ILOG Source Code.  No modifications may be made to the  
//  ILOG Source Code.  Any usage of the ILOG Source Code is subject to 
//  the terms and conditions of the ILOG End User License Agreement   
//  applicable to this ILOG software product.
//
///////////////////////////////////////////////////////////////////////////////

package ilog.gauges.rectangular.renderers
{
  import flash.geom.Point;
  
  import ilog.gauges.gaugesClasses.rectangular.RectangularGaugeElement;
  
  import mx.core.UIComponent;

  [DefaultProperty("component")]

  /**
   * The <code>RectangularGaugeWrapper</code> is a wrapper to include any
   * subclass of <code>UIComponent</code> into a rectangular gauge layout.
   *  
   * @mxml
   *  
   * <p>The <code>&lt;ilog:RectangularGaugeWrapper&gt;</code> tag inherits all the properties
   * of its parent classes and adds the following properties:</p>
   *  
   * <pre>
   * &lt;ilog:RectangularGaugeWrapper
   *   <strong>Properties</strong>
   *   component="<i>UIComponent; no default</i>"
   * /&gt;
   * </pre>
   *  
   * @see ilog.gauges.gaugesClasses.rectangular.RectangularGaugeElement
   * @since ILOG Elixir 2.0
   * @includeExample examples/RectangularGaugeWrapperExample.mxml -noswf
   * @ilog.reviewed SH 27 July 08
   */  
  public class RectangularGaugeWrapper extends RectangularGaugeElement
  {
    
    private var _component:UIComponent;

    /**
     *  The component to be included in the rectangular gauge layout. It can be any subclass of <code>UIComponent</code>.
     *  @default null
     *  @ilog.reviewed SH 27 July 08
     *  
     */    
    public function get component():UIComponent
    {
      return _component;
    }

    /**
     * @private
     */    
    public function set component(value:UIComponent):void
    {
      if (_component != null && contains(_component) == true)
        removeChild(_component)
      _component = value;
      addChild(_component);
      invalidateDisplayList();
    }

    /**
     * @private
     */    
    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
    {
      super.updateDisplayList(unscaledWidth, unscaledHeight);
      _component.setActualSize(unscaledWidth, unscaledHeight);
    }

    /**
     * @private
     */        
    protected override function measure():void
    {
      measuredWidth = 0;
      measuredHeight = 0;                
      if (_component != null) {
        measuredWidth = _component.measuredWidth; 
        measuredHeight = _component.measuredHeight;
      }         
    }      
  }
}
